<!-- 提现 -->
<template>
    <view class="page">
        
        <view style="padding: 25rpx;">
            <view class="ni">
                <view style="padding: 30rpx 25rpx;">
                    <view style="font-size: 45rpx; color: #444;">
                        提现金额
                    </view>
                    <view style="display: flex;align-items: center;margin-top: 30rpx;margin-bottom: 30rpx;">
                        <label style="font-size: 45rpx; margin-right: 20rpx;">￥</label>
                        <span v-if="!money" class="cursor-blink">&nbsp;</span>
                        <input :placeholder="'最低'+system.plat_min+'元'"  style="font-size: 75rpx;" v-model="money"/>
                    </view>
                    <view style="border-top: 1rpx solid #e8e8e8;">
                        <view style="display: flex;justify-content: space-between; align-items: center;line-height: 80rpx;">
                            <view >
                                <view style="font-size: 26rpx; color: #888;">可用余额：{{user.money || '0.00'}}</view>
                            </view>
                            <view @click="money=user.money" style="color: #398fff;font-size: 32rpx;">全部提现</view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
     
        <view style="margin:15px auto;display:block;width: 92%;">
            <button class="button1" @tap="submit()">提现</button>
        </view>
        <payment v-if="showpay" :tyxina="true" @tixian="pay" @payresult='payresult' title="支付" :getmoney="money" :fix='fix'
            type="redpacket" :id="id" @close="showpay=false;"></payment>

    </view>
</template>

<script>
    import http from "../../library/http.js"
    import payment from '@/components/payment.vue'
    export default {
        components:{
            payment
        },
        data() {
            return {
                money: '',
                pwd: '',
                fix: true,
                user: uni.getStorageSync('userInfo'),
                system: uni.getStorageSync('system'),
                bank: uni.getStorageSync('bank'),
                bank_arr: [],
                bankid: 0,
                bank_id: 0,
                showpay:false,
                payment:{
                    
                },
            }
        },
        methods: {
            payresult(e) {
                console.log('打印',e)
            },
            bindbankChange(e) {
                var num = e.target.value;

                this.setbanknum(num);
            },

            setbanknum(num) {
                this.bankid = num;

                var i = 0;
                for (var ii in this.bank) {
                    if (i == num) {
                        this.bank_id = this.bank[ii].id
                    }
                    i++;
                }

            },
            getuserinfo() {
                var postdata = {
                    id: uni.getStorageSync('access_token')
                };
                http.setWait(false).post('user.php?act=userinfo', postdata).then(res => {
                    this.user = res.data;
                    uni.setStorageSync('userInfo', this.user)
                })

            },
            setbank() {
                var arr = [];

                for (var i = 0; i < this.bank.length; i++) {

                    arr.push(this.bank[i]['number']);
                }
                this.bank_arr = arr;
                this.setbanknum(0);
            },
            getbank() {
                this.setbank();
                var postdata = {
                    userid: uni.getStorageSync('access_token')
                };
                http.setWait(false).post('user.php?act=mybank', postdata).then(res => {
                    this.bank = res.data;

                    uni.setStorageSync('bank', this.bank)
                    this.setbank();


                })
            },
            submit() {
                var money = this.money;
                if (money == "") {

                    uni.showToast({
                        title: '请填写提现金额',
                        icon: 'none'
                    })

                    return false;
                }

                if (isNaN(money)) {

                    uni.showToast({
                        title: '提现金额必须为数字',
                        icon: 'none'
                    })
                    return false;
                }
                if (parseFloat(money) - parseFloat(this.system.plat_min) < 0) {
                    uni.showToast({
                        title: '每次最少提现' + this.system.plat_min + '元！',
                        icon: 'none'
                    })

                    return false;
                }
                if (parseFloat(money) - parseFloat(this.user.money) > 0) {

                    uni.showToast({
                        title: '提现金额不能大于' + this.user.money + '元！',
                        icon: 'none'
                    })

                    return false;
                }
                if (parseFloat(money) - parseFloat(this.system.plat_max) > 0) {
                    uni.showToast({
                        title: '每次最多提现' + this.system.plat_max + '元！',
                        icon: 'none'
                    })

                    return false;
                }

                if (this.pwd == "") {
                    this.showpay = true
                    return false;
                }
               
                if (this.$action.check_userlock() == false) return false;

                // this.payinfo = 
                


            },
            
            pay(pwd){
                this.showpay = false
                
                http.setWait(true).post('pay.php?act=plat', {
                    money: this.money,
                    bankid: this.bank_id,
                    pwd: pwd,
                    userid: this.user.id
                }).then(res => {
                    this.getuserinfo();
                    this.money = ''
                    uni.showModal({
                        title: '提示',
                        content: "提现已提交，请耐心等待",
                        showCancel: true,
                        cancelText: '关闭',
                        confirmText: '查看账单',
                        success: res => {
                            if (res.confirm) {
                                uni.redirectTo({
                                    url: "/pages/mine/order"
                                })
                            }
                        }
                    });
                
                })
            }
        },
        onLoad() {

            this.getuserinfo();
            this.getbank();

        }

    }
</script>

<style lang="scss" scoped>
    @import "@/static/css/user.css";

    .page {
        background-color: #ebebeb;
        min-height: 100vh;
    }
.cursor-blink {
            display: inline-block;
            width: 1px;
            height: 100rpx;
            background-color: red;
            animation: blink 1s infinite steps(1, start);
        }
        /*这里设置动画blink*/
        @keyframes blink {
            0%, 100% {
                background-color: #000;
                color: #aaa;
            }
            50% {
                background-color: #fff; /* not #aaa because it's seem there is Google Chrome bug */
                color: #000;
            }
        }
    
    .profile,
    .login-lines1 {
        background-color: #fff;
        margin: 10px auto;
        width: 100%;
        vertical-align: middle;
    }

    .profile li {
        vertical-align: middle;
    }

    .profile li:first-child {
        width: 120px
    }

    .profile li:last-child {
        width: calc(100% - 130px)
    }

    .input1 {
        max-width: 150px;
    }
</style>